package kr.hkit.powerjava.chapter22.work2;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

import kr.hkit.powerjava.chapter22.work2.dao.DepartmentManagerImpl;
import kr.hkit.powerjava.chapter22.work2.dao.StudentManagerImpl;
import kr.hkit.powerjava.chapter22.work2.vo.Department;
import kr.hkit.powerjava.chapter22.work2.vo.Student;


public class TestMain {
	public static void main(String[] args) {
		ArrayList<Student> stdList= new ArrayList<>();
		ArrayList<Department> deptList= new ArrayList<>();
		StudentManagerImpl sm= new StudentManagerImpl(stdList);
		DepartmentManagerImpl dept= new DepartmentManagerImpl(deptList);
		//추가(Student)
		Student std1= new Student(1, "김태희", 90, 90, 90);
		sm.addItem(std1);
		Student std2= new Student(2, "제시카", 89, 79, 77);
		sm.addItem(std2);
		sm.addItem(new Student(3, "김주하", 80, 80, 80));
		sm.addItem(new Student(4, "이민정", 78, 79, 89));
		sm.addItem(std1);
		//추가(Department)
		Department dept1= new Department(1, "컴    공",1);
		dept.addItem(dept1);
		Department dept2= new Department(2, "정치행정",2);
		dept.addItem(dept2);
		Department dept3= new Department(3, "유아교육",3);
		dept.addItem(dept3);
		//삭제
		/*sm.delItem(std1);
		sm.delItem(std2);*/
		//검색
		/*Student searchItem= new Student(1, "김태희");
		String result=sm.searchItem(searchItem)?"존재":"없음";
		System.out.println(searchItem.getStdNum()+":"+searchItem.getStdName()+"="+result);
		
		Department searchItem1= new Department(1, "정치행정");
		String rs=dept.searchItem(searchItem1)?"해당과목있음?":"해당과목없음";
		System.out.println(searchItem1.getDeptNo()+":"+searchItem1.getDeptName()+"="+rs);*/
		Map<Integer, Department> m = new HashMap<Integer, Department>();
		m.put(1,new Department(1, "컴퓨터공학"));
		m.put(2,new Department(2, "국제통상"));
		Map<Integer, Student> s= new HashMap<Integer,Student>();
		s.put(1,new Student(2, "홍길동"));
		System.out.println(m);
		System.out.println(s);
		//수정
		Student updateItem= new Student(1, "김태희", 91, 93, 94);
		sm.updateItem(updateItem);
		//출력
		sm.prnItems();
		System.out.println("총점순 정렬(내림차순)");
		Comparator<Student> totalCom= new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return (int)(o2.getTotal()-o1.getTotal());
			}
		};
		//Department
		dept.prnItems();
		System.out.println("층수별 정렬");
		Comparator<Department> com= new Comparator<Department>() {
			@Override
			public int compare(Department o1, Department o2) {
				return o2.getFloor()-o1.getFloor();
			}
		};
		dept.prnItems(com);
		/*sm.prnItems(totalCom);
		System.out.println("이름순 정렬");
		Comparator<Student> com= new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				// TODO Auto-generated method stub
				return o1.getStdName().hashCode()-o2.getStdName().hashCode();
			}
		};
		sm.prnItems(com);
		
		System.out.println("국어점수 정렬");
		//무명클래스
		sm.prnItems(new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return o2.getKor()-o1.getKor();
			}
		});
		for(Student std:stdList){
			System.out.println(std);
		}
		Collections.shuffle(stdList);
		Student std= null;
		Iterator<Student> iterator= stdList.iterator();
		while(iterator.hasNext()){
			std=iterator.next();
			System.out.println(std);
		}*/
	}
	
}
